package com.example.dao;

import com.example.entity.*;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

public interface OrderMapper {
    @Delete("delete from `order` where o_id = #{o_id}")
    int deleteOrder(int o_id);
    @Update("update flight_status set economy_space = flight_status.economy_space + 1 where f_id=#{f_id}")
    void updateAddEconomySpace(int f_id);
    @Update("update flight_status set first_space = flight_status.first_space + 1 where f_id=#{f_id}")
    void updateAddFirstSpace(int f_id);
    @Update("update flight_status set business_space = flight_status.business_space + 1 where f_id=#{f_id}")
    void updateAddBusinessSpace(int f_id);
    @Update("update passenger set order_num = order_num - 1 where passenger_id=#{passenger_id}")
    void updatePassengerOrderNum(int passenger_id);

    @Select("select * from passenger where passenger_id = #{passenger_id}")
    Passenger getPassengerByPassengerId(int passenger_id);
    @Select("select * from flight where f_id = #{f_id}")
    Flight getFlightByFlightId(int f_id);
    @Select("select f_model from flight where f_id = #{f_id}")
    String getFlightModelByFlightId(int f_id);
    @Select("select * from plane where p_model = #{p_model}")
    Plane getPlaneByPlaneModel(String p_model);
    @Select("select date from flight_status where f_id = #{f_id}")
    Date getFlightDateByFlightId(int f_id);
    @Select("select status from flight_status where f_id = #{f_id}")
    String getFlightStatusByFlightId(int f_id);

    @Select("select passenger_ID_card from passenger where passenger_id=#{p_id}")
    String getPassengerIDcardByPid(int p_id);
    @Select("select o_money from `order` where o_id=#{o_id}")
    double getOrderMoneyByOid(int o_id);
    @Select("select money from bank where u_ID_card=#{u_ID_card}")
    double getBankMoneyByUserIDcard(String u_ID_card);
    @Update("update `order` set status = '已支付' where o_id=#{o_id}")
    int updateOrderStatus(int o_id);
    @Update("update passenger set order_num = order_num+1 where passenger_id=#{p_id}")
    int updatePassengerOrderNumByPid(int p_id);
    @Update("update bank set money=#{money} where u_ID_card=#{u_ID_card}")
    int updateBankMoneyByUserIDcard(@Param("u_ID_card") String u_ID_card, @Param("money") double money);

    //订单详情
    @Select("select * from `order` where id = #{order_id}")
    Order getOrderByOrderId(int order_id);
    @Select("select * from ticket where order_id = #{order_id}")
    List<Ticket> getTicketByOrderId(int order_id);
    @Select("SELECT p.passenger_name, passenger_sex, ID_type, passenger_ID_card, p.type, p.passenger_age FROM passenger p " +
            "JOIN ticket ON p.passenger_id = ticket.passenger_id " +
            "WHERE ticket.order_id = #{order_id}")
    List<Passenger> getPassengerListByOrderId(int order_id);
//    Flight getFlightByFlightId(int f_id);  //已存在
    @Select("select * from plane p join flight f on p.plane_id = f.plane_id where f.f_id = #{f_id}")
    List<Plane> getPlaneListByFId(int f_id);

}
